package jm.nj.demo10mian.demo01;

import java.io.File;

/*
 * File类的获取功能
 * */
public class Demo05File {
    public static void main(String[] args) {
        //method_1();
       // method_2();
        method_3();
    }
/*
* Sting getPath()将此抽象路径名转换为一个路径名字符串
* 与toString 一样
* */
    private static void method_3() {
        File file = new File("c:\\a.txt");
        System.out.println(file);
        System.out.println(file.getPath());
        System.out.println(file.toString());
    }

    /*
*String getName()
* 返回路径中表示的文件或者文件夹名
 * 获取路径中最后部分的名字
* */
    private static void method_2() {
        File file = new File("D:\\Work_20170327\\day10\\a.txt");
        String name = file.getName();
        System.out.println(name);

        file = new File("D:\\Work_20170327\\day1011111adfsadf");
        name = file.getName();
        System.out.println(name);
    }

    /*
     * File getAbsoluteFile () 返回此抽象路径名的绝对路径
     * String getAbsolutePath();返回此抽象路径名的绝对路径名字符串
     * 获取绝对路径
     * */
    private static void method_1() {
        File file1 = new File("fsf");
        File file2 = file1.getAbsoluteFile();
        System.out.println(file2);

        file1 = new File("first");
        String absolute = file1.getAbsolutePath();
        System.out.println(absolute);
    }

    /*@Test
	public void method(){
		System.out.println("单元测试");
	}*/

}
